<?php

/* @var $this yii\web\View */

use yii\helpers\Html;
use daixianceng\echarts\ECharts;

$this->title = '销售量对比';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-detail">
    <div>
        <?php
        $readonly=true;
        if(\Yii::$app->authManager->checkAccess(Yii::$app->user->id, 'admin'))
        {
            $readonly=false;
        }
        ?>
        <?= Html::label('航空公司', 'airline', []) ?>
        <?= Html::input('text', 'airline', $airline, ['id'=>'myairline','readonly'=>$readonly]) ?>
        <?= Html::label('代理人', 'agent', []) ?>
        <?= Html::input('text', 'agent', $agent, ['id'=>'myagent']) ?>
        <?= Html::button('查询', ['id' => 'chaxun']) ?>
    </div>
    <?= Html::jsFile('@web/js/echarts.min.js') ?>
    <div id="main" style="height: 400%;width: 100%;">

    </div>

    <?php $this->beginBlock('myjs') ?>
    function getdata() {
    var myChart = echarts.init(document.getElementById('main'));
    myChart.showLoading();
    var airline=$("#myairline").val();
    var agent=$("#myagent").val();
    $.ajax({
    type: "POST",
    url: '<?=\Yii::getAlias('@web')?>/compare/ajaxcount',
    dataType: "json",
    data:
    {
    csrfToken:"<?= Yii::$app->request->csrfToken ?>",
    airline:airline,
    agent:agent,
    },
    success: function(data)
    {
    myChart.hideLoading();
    var option = option = {
    title: {
    text: '销售量对比',
    },
    tooltip: {
    trigger: 'axis'
    },
    legend: {
    data:['原始值','预测值']
    },
    toolbox: {
    show: true,
    feature: {
    dataView: {readOnly: true},
    magicType: {type: ['line', 'bar']},
    saveAsImage: {}
    }
    },
    xAxis:  {
    type: 'category',
    boundaryGap: false,
    data: data.X
    },
    yAxis: {
    type: 'value',
    axisLabel: {
    formatter: '{value}'
    }
    },
    series: [
    {
    name:'原始值',
    type:'line',
    data:data.iY,
    },
    {
    name:'预测值',
    type:'line',
    data:data.nY,
    }
    ]
    };
    myChart.setOption(option);
    },
    error: function(jqXHR)
    {
    alert("发生错误：" + jqXHR.status);
    },
    });
    }
    getdata();
    $("#chaxun").click(function(){
    getdata();
    });
    <?php $this->endBlock() ?>
    <?php $this->registerJs($this->blocks['myjs'], \yii\web\View::POS_READY); ?>

</div>

<script>

</script>
